import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import '../../provider/details_info.dart';

class DetailsTab extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 15.0),
      child: Consumer<DetaiInfoProvider>(
        builder: (context, DetaiInfoProvider detaiInfoProvider, child) {
          bool isLeft = detaiInfoProvider.isLeft;
          return Row(
            children: <Widget>[
              _tabItem(context, isLeft, '详细'),
              _tabItem(context, !isLeft, '评论'),
            ],
          );
        },
      ),
    );
  }

  Widget _tabItem(context, bool isActive, String desc) {
    Color color = isActive ? Colors.pink : Colors.black26;
    bool flag = desc == '详细' ? true : false;
    return InkWell(
      onTap: () {
        Provider.of<DetaiInfoProvider>(context, listen: false).changeActive(flag);
      },
      child: Container(
        width: ScreenUtil().setWidth(375),
        padding: EdgeInsets.all(10.0),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            bottom: BorderSide(
              width: 1.0,
              color: color
            )
          ),
        ),
        child: Text(
          desc,
          style: TextStyle(
            color: color
          ),
        ),
      ),
    );
  }
}